<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategyComment.css" />
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
		<meta content="yes" name="apple-mobile-web-app-capable"/>
		<meta content="black" name="apple-mobile-web-app-status-bar-style"/>
		<meta content="telephone=no" name="format-detection"/>
		<link href="/css/style.css" rel="stylesheet" type="text/css"/>
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
		<link rel="stylesheet" href="/css/reset.css">
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<!--<link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">-->
		<link rel="stylesheet" href="/css/editTravels.css"/>
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/jquery-form/jquery.form.js"></script>
		<script src="/js/plugins/eleditor/Eleditor.min.js"></script>
		<script src="/js/common.js"></script>
		<script>
			$(function () {
				var params = getParams();
                var userStr = sessionStorage.getItem("user")
                var user = JSON.parse(userStr);
                console.log(user.id);
                $.get("/strategyComments/"+params.id,function (data) {
                    console.log(data);
                    $("#commentDetail").renderValues(data,{
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).attr("href")+value)
                        }
					})
					//星星展示
					var stars=$(".comment-star")
                    for (i=0;i<stars.length;i++){
                        //遍历,把第i个取出,imgurl已经是选择了的,这样吧document对象转换成Jquery对象
                        var temp=$(stars[i])
                        //拆分图片,变成一个数组
                        var star =temp.html();
                        //清空临时变量
                        temp.empty();
                        for (j=0;j<star;j++){
                            temp.append("<i class='"+"fa fa-star"+"'></i>");
                        };

                    };
                    //图片展示
                    var imgUrls=$(".imgUrls")
                    //有多少个imgUrl,把他们遍历,然后再拆分
                    for (i=0;i<imgUrls.length;i++){
                        //遍历,把第i个取出,imgurl已经是选择了的,这样吧document对象转换成Jquery对象
                        var temp=$(imgUrls[i])
                        //拆分图片,变成一个数组
                        var imgs =temp.html().split(";");
                        //清空临时变量
                        temp.empty();
                        for (j=0;j<imgs.length-1;j++){
                            temp.append("<li><img src='"+imgs[j]+"' width='50px' style='margin-right:5px'/></li>");
                        };

                    };
                   //查询是否已经被点赞
                    var status=1;
                    var authorId=data.user.id;
                    $.get("messages/like", {authorId: authorId, "liker.id": user.id,state:2,bindId:params.id}
                    ,function (data) {
                        if (!data){
                            $("#likeBtn").css({"color": "red"});
                            status=2;
                        }
                    })



                    //设置状态,状态为2就不能发送指令,点赞事件
                    $("#likeBtn").click(function () {
                        if (status == 1) {
                            $(this).css({"color": "red"})
                            $.post("/messages/like", {authorId: authorId, "liker.id": user.id, state: 2,bindId:params.id})
                            status = 2;
                        }else {
                            $(this).css({"color": "black"})
                            $.ajax({
                                url: "/messages/like",
                                data:{authorId: authorId, "liker.id": user.id, state: 2,bindId:params.id},
                                type: "DELETE",
                                success: function () {
                                }
                            })
                            //删除完了,又可以点赞
                            status = 1;
                        }
                    })
                })

				//富文本框
                var Edr = new Eleditor({
                    el: '#contentEditor',
                    toolbars: [
                        'insertText',
                        'editText',
                        'delete',
                        'undo',
                        'cancel'
                    ]
                })


				$("#saveBtn").click(function (data) {
                    if (!Edr.getContent().replace(/^\s*/,"").length==0){
                    $.post("/strategyComments/saveSubComment",{id:params.id,content:Edr.getContent(),"user.id":user.id},function (data){
                        if (data.success) {
                            location.reload()
                        }
					})
					}else {
                        $(document).dialog({
                            type : 'confirm',
                            style: 'default',  // default、ios、android
                            titleText: '错误!',
                            content: "输入为空!请重新输入",
                        });
                    }
                })

                $.get("/strategyComments/"+params.id+"/subComment",function (data) {
                    console.log(data);
                    $("#commentId").html(data.length)
                    $("#comment").renderValues({list:data})
                })
            })
		</script>

	</head>

	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="javascript:history.go(-1);">
						<span><i class="fa fa-chevron-left"></i></span>
					</a>
				</div>
				<div class="col">
					<span>点评详情</span>
				</div>
				<div class="col"></div>
			</div>
		</div>
<br>
		<div class="comment">
			<div class="container " id="commentDetail">
				<div class="row">
					<div class="col-2 comment-head">
						<p class="authorName"><span render-html="user.nickName"></span></p>
						<a href="userProfiles.html" data-id="43">
							<img class="rounded-circle" render-src="user.headImgUrl">
						</a>
						<button class="btn" id="followBtn"><i class="fa fa-hand-o-right"> </i> 关注</button>
					</div>
					<div class="col">
							<span class="comment-star" render-html="starNum">
							</span>

						<span class="comment-date" render-html="commendTime"></span>
						<div class="comment-content">
							<p render-html="content"></p>
						</div>
						<ul class="comment-img imgUrls" render-html="imgUrls">

						</ul>

						<div class="comment-link">
							<a href="strategyCatalogs.html?strategyId=" render-fun="setHref" render-key="strategy.id">
								<img render-src="strategy.coverUrl"> <span render-html="strategy.title"></span>
								<i class="fa fa-angle-right fa-2x"></i>
							</a>
						</div>

					</div>
				</div>
			</div>

			<div class="count d-flex justify-content-between">
				<div class="p-2">评论<span id="commentId"></span></div>
				<div class="p-2 ">
				<i class="fa fa-thumbs-o-up"  id="likeBtn"> </i>
				</div>
			</div>
		</div>
		<div id="comment">
			<div render-loop="list">
				<div class="container row comment">
					<div class="col-3 comment-head">
						<a href="userProfiles.html" >
							<img class="rounded-circle"
								 render-src="list.user.headImgUrl">
						<p class="authorName"><span render-html="list.user.nickName">dafei</span></p>
						</a>
					</div>
					<div class="col comment-right">
						<div class="comment-content">
							<a href="strategyComment.html" >
								<p  render-html="list.content"></p>
							</a>
						</div>
					</div>
				</div>
			</div>
		</div>

		<h6 href="#">点击评论</h6>
		<div id="contentEditor" >
		</div>
		<br/>
		<!--<div class="operation">
			<div class="d-flex justify-content-between">
                <div class="p-2"><i class="fa fa-commenting-o"></i><span  id="">添加你的评论</span>></div>
				<div class="p-2"><i class="fa fa-star-o"></i> 收藏</div>
			</div>
		</div>-->
		<div class="container d-flex">
			<div class="p-2  flex-fill">
				<div class="p-2"><i class="fa fa-commenting-o"></i><span  id="saveBtn">添加你的评论</span>></div>
			</div>
			<div class="p-2  flex-fill" style=""><i class="fa fa-star-o" id="collectBtn"></i>
			</div>
		</div>


</body>

</html>